package com.gm.wj.controller;

import com.gm.wj.result.Result;
import com.gm.wj.result.ResultFactory;
import com.gm.wj.service.AdminMenuService;
import com.gm.wj.service.AdminPermissionService;
import com.gm.wj.util.SysLoging;
import io.swagger.annotations.Api;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Menu controller.
 *
 * @author Evan
 * @date 2019/11
 */
@Api(tags = "权限管理相关接口")
@RestController
public class MenuController {
    @Autowired
    AdminMenuService adminMenuService;
    @Autowired
    AdminPermissionService adminPermissionService;

    @GetMapping("/api/menu")
    @SysLoging("加载菜单列表信息") //根据SysLoging的注解信息，进行方法的注释
    public Result menu() {
        return ResultFactory.buildSuccessResult("查询成功",adminMenuService.getMenusByCurrentUser());
    }


    @GetMapping("/api/buttonMenu")
    @SysLoging("加载权限列表信息")
    public Result buttonMenu() {
        String username = (String) SecurityUtils.getSubject().getPrincipal();
        if (username == null || username.equals("") ) {
            return ResultFactory.buildFailResult("未登录");
        }
        return ResultFactory.buildSuccessResult("查询成功",adminPermissionService.listPermissionURLsByUser(username));
    }

    @GetMapping("/api/admin/role/menu")
    @SysLoging("加载菜单列表信息") //根据SysLoging的注解信息，进行方法的注释
    public Result listAllMenus() {
        return ResultFactory.buildSuccessResult("查询成功",adminMenuService.getMenusByRoleId(1));
    }

    @GetMapping("/api/admin/role/menuAll")
    @SysLoging("加载菜单列表信息") //根据SysLoging的注解信息，进行方法的注释
    public Result listAllMenusAll() {
        return ResultFactory.buildSuccessResult("查询成功",adminMenuService.getMenusAll());
    }
}
